{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}/Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/CareyMitchellPaula_replication_RP.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}26 Oct 2021, 10:10:31
{txt}
{com}.         
. 
. ***********************************************
. * Figures using country-year format 
. ***********************************************
. 
.         * load data in country-year format
.         use "pgmdv2_countryyear.dta"
{txt}
{com}.         
.         * aggregate data to year-format
.         
.                 * all pgms per year
.                 sort year
{txt}
{com}.                 bysort year: egen presence_sum=total(presence_count)
{txt}
{com}.         
.                 * informal pgms per year
.                 bysort  year: egen presence_informal_sum=total(presence_informal_count) 
{txt}
{com}.                 
.                 * semi-officials pgms per year
.                 bysort  year: egen presence_semi_sum=total(presence_semiofficial_count) 
{txt}
{com}.                 
.                 * countries with PGM presence per year
.                 bysort year: egen presence_country = total(presence)
{txt}
{com}.                 
.                 * countries with PGMs fromed by government per year
.                 bysort year: egen presence_gov_formed_country = total(presence_govformed)
{txt}
{com}.                 
.                 * countries with newly government-formed PGMs per year
.                 bysort year: egen presence_gov_formed_on_country = total(presence_gov_formed_on)
{txt}
{com}.                 
.         * collapse data for plotting
.         collapse (first) presence_sum presence_informal_sum presence_semi_sum presence_country presence_gov_formed_country presence_gov_formed_on_country, by(year)
{txt}
{com}.         
.         
. 
. * Figure 1. Number of PGMs over time
. *--------------------------------------------------
. 
.         #delimit ;
{txt}delimiter now ;
{com}.                 twoway line presence_sum presence_informal_sum presence_semi_sum year,
>                 sort 
>                 lcolor(black ebblue emidblue)
>                 xline(0, lstyle(grid) lcolor(white) lwidth(*1.5))
>                 xlabel(1981 1985(5)2010 2014, grid glcolor(white)) 
>                 ylabel(,nogrid)
>                 xtitle("")
>                 ytitle("Number of PGMs")
>                 xline(2007, lpattern(shortdash) lcolor(black)) 
>                 legend(order (1 "Any PGM" 2 "Informal PGMs" 3 "Semi-official PGMs") 
>                 size(small) keygap(*0.5) symysize(*0.5) region(lcolor(white)) rows(1) cols(3))
>                 note("Excluding Somalia 1981-2011 & Lebanon 1981-2007")
>                 graphregion(color(white))
>         ;
{res}{txt}
{com}.         #delimit cr     
{txt}delimiter now cr
{com}.         graph export "figures/Figure1.pdf", replace
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure1.pdf written in PDF format)

{com}.         
. 
. * Figure 2. Distribution of PGMs across countries and time
. *--------------------------------------------------
. 
.         #delimit ;
{txt}delimiter now ;
{com}.                 twoway line presence_country presence_gov_formed_country presence_gov_formed_on_country year, 
>                 sort 
>                 xlabel(1981 1985(5)2010 2014)   
>                 title("Countries with PGMs")
>                 ytitle("Number of countries with PGMs")
>                 title("")
>                 ylabel(0(10)60,nogrid)
>                 xline(2007, lpattern(shortdash) lcolor(black)) 
>                 lcolor(black ebblue eltgreen)
>                 legend(order (1 "Any PGM" 2 "PGM formed by government" 3 "New PGM formed by government") 
>                 size(small) keygap(*0.5) symysize(*0.5) region(lcolor(white)) rows(3) cols(1))  
>                 note("Excluding Somalia 1981-2011 & Lebanon 1981-2007")
>                 graphregion(color(white))
>         ;
{res}{txt}
{com}.         #delimit cr  
{txt}delimiter now cr
{com}.         graph export "figures/Figure2.pdf", replace 
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure2.pdf written in PDF format)

{com}.         
. 
. 
. ***********************************************
. * Figures using group format 
. ***********************************************
.         
.         * load data in group format
.         clear all
{txt}
{com}.         use "pgmdv2_group.dta"
{txt}
{com}. 
.         
.         
. * Figure 3. Primary characteristic of PGM membership, by government formation
. *--------------------------------------------------
.                         
.         * create dummies for primary membership plotting
.         
.                 * for ethnicity
.                 gen prim_ethnicity = primary_mem
{txt}
{com}.                 recode prim_ethnicity (0=.)
{txt}(prim_ethnicity: 117 changes made)

{com}.                 recode prim_ethnicity (9=.)
{txt}(prim_ethnicity: 4 changes made)

{com}.                 recode prim_ethnicity (2/8=0) 
{txt}(prim_ethnicity: 315 changes made)

{com}.                 recode prim_ethnicity (0=1) if alt_primary_mem==1 
{txt}(prim_ethnicity: 15 changes made)

{com}.         
.                 * for local
.                 gen prim_local = primary_mem
{txt}
{com}.                 recode prim_local (0=.)
{txt}(prim_local: 117 changes made)

{com}.                 recode prim_local (9=.)
{txt}(prim_local: 4 changes made)

{com}.                 recode prim_local (1/2=0) (3=1) (4/8=0)
{txt}(prim_local: 383 changes made)

{com}.                 recode prim_local (0=1) if alt_primary_mem==3
{txt}(prim_local: 5 changes made)

{com}.         
.                 * for non-civilian
.                 gen prim_non_civilian = primary_mem
{txt}
{com}.                 recode prim_non_civilian  (0=.)
{txt}(prim_non_civilian: 117 changes made)

{com}.                 recode prim_non_civilian  (9=.)
{txt}(prim_non_civilian: 4 changes made)

{com}.                 recode prim_non_civilian (1/4=0) (5=1) (6/8=0)
{txt}(prim_non_civilian: 383 changes made)

{com}.                 recode prim_non_civilian (0=1) if alt_primary_mem==5
{txt}(prim_non_civilian: 0 changes made)

{com}.         
.                 * for political
.                 gen prim_political = primary_mem
{txt}
{com}.                 recode prim_political (0=.)
{txt}(prim_political: 117 changes made)

{com}.                 recode prim_political (9=.)
{txt}(prim_political: 4 changes made)

{com}.                 recode prim_political (1/5=0) (6=1) (7/8=0)
{txt}(prim_political: 383 changes made)

{com}.                 recode prim_political (0=1) if alt_primary_mem==6
{txt}(prim_political: 6 changes made)

{com}.         
.                 * for religious
.                 gen prim_reli = primary_mem
{txt}
{com}.                 recode prim_reli (0=.)
{txt}(prim_reli: 117 changes made)

{com}.                 recode prim_reli (9=.)
{txt}(prim_reli: 4 changes made)

{com}.                 recode prim_reli (1/6=0) (7=1) (8=0)
{txt}(prim_reli: 383 changes made)

{com}.                 recode prim_reli (0=1) if alt_primary_mem==7
{txt}(prim_reli: 6 changes made)

{com}.         
.                 * for other (incl. other/nationalist/ideological)
.                 gen prim_other = primary_mem
{txt}
{com}.                 recode prim_other (0=.)
{txt}(prim_other: 117 changes made)

{com}.                 recode prim_other (9=.)
{txt}(prim_other: 4 changes made)

{com}.                 recode prim_other (1=0) (2=1) (3=0) (4=1) (5/7=0) (8=1)
{txt}(prim_other: 383 changes made)

{com}.                 recode prim_other (0=1) if alt_primary_mem==2 | alt_primary_mem==4
{txt}(prim_other: 8 changes made)

{com}.         
.         
.         * distribution pgms used in graph
.         gen diff= prim_ethnicity + prim_local + prim_non_civilian  + prim_political + prim_reli + prim_other
{txt}(121 missing values generated)

{com}.         tab diff gov_formed if gov_formed <3 // tab cases with clear government formation (gov_formed < 3)

           {txt}{c |} formed by government
      diff {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}       168        143 {txt}{c |}{res}       311 
{txt}         2 {c |}{res}        27         11 {txt}{c |}{res}        38 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 

{txt}
{com}.                 * 195 not formed by government
.                 * 154 formed by government
.                 * 38 with 2 primary memberships
.                 
.         * get percentages 
.         tab prim_ethnicity gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

prim_ethni {c |} formed by government
      city {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       136        134 {txt}{c |}{res}       270 
           {txt}{c |}{res}     69.74      87.01 {txt}{c |}{res}     77.36 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        59         20 {txt}{c |}{res}        79 
           {txt}{c |}{res}     30.26      12.99 {txt}{c |}{res}     22.64 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         tab prim_local gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

           {c |} formed by government
prim_local {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       165         97 {txt}{c |}{res}       262 
           {txt}{c |}{res}     84.62      62.99 {txt}{c |}{res}     75.07 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        30         57 {txt}{c |}{res}        87 
           {txt}{c |}{res}     15.38      37.01 {txt}{c |}{res}     24.93 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         tab prim_non_civilian gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

prim_non_c {c |} formed by government
   ivilian {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       166        129 {txt}{c |}{res}       295 
           {txt}{c |}{res}     85.13      83.77 {txt}{c |}{res}     84.53 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        29         25 {txt}{c |}{res}        54 
           {txt}{c |}{res}     14.87      16.23 {txt}{c |}{res}     15.47 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         tab prim_reli gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

           {c |} formed by government
 prim_reli {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       156        143 {txt}{c |}{res}       299 
           {txt}{c |}{res}     80.00      92.86 {txt}{c |}{res}     85.67 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        39         11 {txt}{c |}{res}        50 
           {txt}{c |}{res}     20.00       7.14 {txt}{c |}{res}     14.33 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         tab prim_political gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

prim_polit {c |} formed by government
      ical {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       163        133 {txt}{c |}{res}       296 
           {txt}{c |}{res}     83.59      86.36 {txt}{c |}{res}     84.81 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        32         21 {txt}{c |}{res}        53 
           {txt}{c |}{res}     16.41      13.64 {txt}{c |}{res}     15.19 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         tab prim_other gov_formed if gov_formed <3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

           {c |} formed by government
prim_other {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       162        123 {txt}{c |}{res}       285 
           {txt}{c |}{res}     83.08      79.87 {txt}{c |}{res}     81.66 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        33         31 {txt}{c |}{res}        64 
           {txt}{c |}{res}     16.92      20.13 {txt}{c |}{res}     18.34 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       195        154 {txt}{c |}{res}       349 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         
.                 * not formed by government: 
.                         * 30.26% ethnic, 15.38% local, 14.87% non-civilian, 20.00% religious, 16.41% political, 16.92% other
.                 * formed by government: 
.                         * 12.99% ethnic; 37.01% local, 16.23% non-civilian, 7.14% religious, 13.64% political, 20.13% other
. 
.         * Figure 3
.         #delimit ;
{txt}delimiter now ;
{com}.                 graph hbar prim_ethnicity prim_local prim_non_civilian  prim_reli prim_political prim_other if gov_formed <3 , 
>                 over(gov_formed, relabel(1 "No" 2 "Yes")) stack percent
>                 graphregion(color(white))
>                 ylabel( none, nogrid)
>                 yscale(lstyle(none))
>                 ytitle("")
>                 bar(1, color(black*0.95)) bar(2, color(black*.73)) bar(3, color(black*0.55)) bar(4, color(black*0.40)) bar(5, color(black*0.3))
>                 bar(6, color(black*0.25))
>                 legend(row(2) col(3))
>                 legend(lab(1 "Ethnic") lab(2 "Local") lab(3 "Non-civilian") lab(4 "Religious") lab(5 "Political") lab(6 "Other")) 
>                 legend(size(small) position(7) bmargin(small)  region(lcolor(white)))
>                 ttext(3 23   "12.99%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(27 23  "37.01%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(51 23  "16.23%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(63 23   "7.14%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(72 23  "13.64%" "", place(e) size(vsmall) orientation(horizontal) col(white)) 
>                 ttext(88 23  "20.13%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(11 78  "30.26%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(30 78  "15.38%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(44 78  "14.87%" "", place(e) size(vsmall) orientation(horizontal) col(white))  
>                 ttext(59 78  "20.00%" "", place(e) size(vsmall) orientation(horizontal) col(white))
>                 ttext(75 78  "16.41%" "", place(e) size(vsmall) orientation(horizontal) col(white)) 
>                 ttext(89 78  "16.92%" "", place(e) size(vsmall) orientation(horizontal) col(white)) 
>         ;
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         graph export "figures/Figure3.pdf", replace 
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure3.pdf written in PDF format)

{com}. 
.         
.         
. * Figure 4. Types of violence committed, three most common combinations
. *--------------------------------------------------
.         
.         * get most combinations 
.                 
.                 * informal PGMs
.                 egen group1 = group(violencetype_kill violencetype_kidnap violencetype_torture violencetype_sexual violencetype_beat) if government_relation==1, label
{res}{txt}(197 missing values generated)

{com}.                 tab group1 if group1 !=1 //only pgms with any reported violence type at all

  {txt}see notes {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
  0 0 0 0 1 {c |}{res}         13        6.28        6.28
{txt}  0 0 0 1 0 {c |}{res}          2        0.97        7.25
{txt}  0 0 0 1 1 {c |}{res}          2        0.97        8.21
{txt}  0 0 1 0 0 {c |}{res}          1        0.48        8.70
{txt}  0 0 1 0 1 {c |}{res}          2        0.97        9.66
{txt}  0 1 0 0 0 {c |}{res}          2        0.97       10.63
{txt}  0 1 0 0 1 {c |}{res}          2        0.97       11.59
{txt}  1 0 0 0 0 {c |}{res}         70       33.82       45.41
{txt}  1 0 0 0 1 {c |}{res}         12        5.80       51.21
{txt}  1 0 0 1 0 {c |}{res}          8        3.86       55.07
{txt}  1 0 0 1 1 {c |}{res}          4        1.93       57.00
{txt}  1 0 1 0 0 {c |}{res}         15        7.25       64.25
{txt}  1 0 1 0 1 {c |}{res}          2        0.97       65.22
{txt}  1 0 1 1 0 {c |}{res}          4        1.93       67.15
{txt}  1 0 1 1 1 {c |}{res}          3        1.45       68.60
{txt}  1 1 0 0 0 {c |}{res}         17        8.21       76.81
{txt}  1 1 0 0 1 {c |}{res}          5        2.42       79.23
{txt}  1 1 0 1 0 {c |}{res}          7        3.38       82.61
{txt}  1 1 0 1 1 {c |}{res}          3        1.45       84.06
{txt}  1 1 1 0 0 {c |}{res}         17        8.21       92.27
{txt}  1 1 1 0 1 {c |}{res}          5        2.42       94.69
{txt}  1 1 1 1 0 {c |}{res}          3        1.45       96.14
{txt}  1 1 1 1 1 {c |}{res}          8        3.86      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        207      100.00
{txt}
{com}.                 
.                 * most common three
.                         * 1 killing: 33.82%                                             (10000)
.                         * 2 killing & kidnapping: 8.21%                         (11000)
.                         * 3 killing, kidnapping, torture: 8.21%         (11100)
.                 
.                 
.                 * semi-official PGMs
.                 egen group2 = group(violencetype_kill violencetype_kidnap violencetype_torture violencetype_sexual violencetype_beat) if government_relation==2, label
{res}{txt}(328 missing values generated)

{com}.                 tab group2 if group2!=1 //only pgms with any reported violence type at all

  {txt}see notes {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
  0 0 0 0 1 {c |}{res}          7        8.14        8.14
{txt}  0 0 0 1 0 {c |}{res}          3        3.49       11.63
{txt}  0 0 0 1 1 {c |}{res}          2        2.33       13.95
{txt}  0 0 1 0 1 {c |}{res}          1        1.16       15.12
{txt}  0 1 0 0 1 {c |}{res}          1        1.16       16.28
{txt}  1 0 0 0 0 {c |}{res}         28       32.56       48.84
{txt}  1 0 0 0 1 {c |}{res}         10       11.63       60.47
{txt}  1 0 0 1 0 {c |}{res}          2        2.33       62.79
{txt}  1 0 0 1 1 {c |}{res}          4        4.65       67.44
{txt}  1 0 1 0 0 {c |}{res}          2        2.33       69.77
{txt}  1 0 1 0 1 {c |}{res}          2        2.33       72.09
{txt}  1 0 1 1 0 {c |}{res}          5        5.81       77.91
{txt}  1 0 1 1 1 {c |}{res}          3        3.49       81.40
{txt}  1 1 0 0 0 {c |}{res}          1        1.16       82.56
{txt}  1 1 0 0 1 {c |}{res}          2        2.33       84.88
{txt}  1 1 1 0 0 {c |}{res}          3        3.49       88.37
{txt}  1 1 1 0 1 {c |}{res}          4        4.65       93.02
{txt}  1 1 1 1 0 {c |}{res}          3        3.49       96.51
{txt}  1 1 1 1 1 {c |}{res}          3        3.49      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}         86      100.00
{txt}
{com}.                 
.                 * most common three
.                         * 1 killing: 32.56%                                             (10000)
.                         * 2 killing & beating: 11.36%                           (10001)
.                         * 3 beating: 8.14%                                                      (00001)
.         
.         * pre-step 1: create indicator variable for most common combinations
.         gen cat1 = 0
{txt}
{com}.         replace cat1 = 1 if group2== 7  // most common combi semi-officials: killing
{txt}(28 real changes made)

{com}.         replace cat1 = 2 if group2== 8  // 2nd most common semi-officials: killing & beating
{txt}(10 real changes made)

{com}.         replace cat1 = 3 if group2== 2  // 3rd most common semi-officials: beating
{txt}(7 real changes made)

{com}.         replace cat1 = 1 if group1== 9  // most common combi informals: killing
{txt}(70 real changes made)

{com}.         replace cat1 = 2 if group1== 17 // 2nd most common combi informals: killing & kidnapping
{txt}(17 real changes made)

{com}.         replace cat1 = 3 if group1== 21 // 3rd most common combi informals: killing, kidnapping & torture
{txt}(17 real changes made)

{com}.         replace cat1=. if group1==. & group2==.
{txt}(21 real changes made, 21 to missing)

{com}.         replace cat1 =. if group1 ==1 | group2==1 // excluding pgms with no reported form of violence
{txt}(190 real changes made, 190 to missing)

{com}.         
.         * pre-step 2: create dummy variables for plotting
.         tab cat1, gen(dum)

       {txt}cat1 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}        144       49.15       49.15
{txt}          1 {c |}{res}         98       33.45       82.59
{txt}          2 {c |}{res}         27        9.22       91.81
{txt}          3 {c |}{res}         24        8.19      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        293      100.00
{txt}
{com}.         
.         * plot and edit graph to hide dummy1 bar = others (necessary, otherwise % wrong)
.         #delimit ;
{txt}delimiter now ;
{com}.                 graph hbar dum2 dum3 dum4 dum1  if government_relation !=0 , 
>                 over(government_relation, relabel(1 "Informal" 2 "Semi-official"))  percent
>                 graphregion(color(white))
>                 ylabel( none, nogrid)
>                 yscale(lstyle(none))
>                 ytitle("")
>                 title ("")
>                 bar(1, color(black*0.9)) bar(2, color(black*.6)) bar(3, color(black*0.4)) bar(4, color(black*0.28))
>                 legend(off)
>                 ttext(1 20  "8.14%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 31  "11.63%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 41  "32.56%" "", place(e) size(small) orientation(horizontal) col(white) ) 
>                 
>                 ttext(35 20  "Beating", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(35 31  "Killing & Beating", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(35 41  "Killing", place(e) size(small) orientation(horizontal) col(black) ) 
>                 
>                 ttext(1 71  "8.21%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 82  "8.21%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 93  "33.82%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 
>                 ttext(35 71  "Killing, Kidnapping & Torture", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(35 82  "Killing & Kidnapping", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(35 93  "Killing", place(e) size(small) orientation(horizontal) col(black) )  
>         ;
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         
.         gr_edit .plotregion1.bars[5].draw_view.setstyle, style(no)
{res}{txt}
{com}.         gr_edit .plotregion1.bars[1].draw_view.setstyle, style(no)
{res}{txt}
{com}.         graph export  "figures/Figure4.pdf", replace
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure4.pdf written in PDF format)

{com}.         
.                 
.                 
. * Figure 5. Reported violence committed by PGM with or without forced membership
. *--------------------------------------------------      
.          
.          * get percentages
.          tab  violencetype_sexual members_coerced if members_coerced < 3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

violencety {c |}    members_coerced
 pe_sexual {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       390         37 {txt}{c |}{res}       427 
           {txt}{c |}{res}     89.86      62.71 {txt}{c |}{res}     86.61 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        44         22 {txt}{c |}{res}        66 
           {txt}{c |}{res}     10.14      37.29 {txt}{c |}{res}     13.39 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       434         59 {txt}{c |}{res}       493 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.          tab  violencetype_kill members_coerced if members_coerced < 3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

violencety {c |}    members_coerced
   pe_kill {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       220         23 {txt}{c |}{res}       243 
           {txt}{c |}{res}     50.69      38.98 {txt}{c |}{res}     49.29 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}       214         36 {txt}{c |}{res}       250 
           {txt}{c |}{res}     49.31      61.02 {txt}{c |}{res}     50.71 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       434         59 {txt}{c |}{res}       493 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.          tab  violencetype_beat members_coerced if members_coerced < 3, col
{txt}
{c TLC}{hline 19}{c TRC}
{c |} Key{col 21}{c |}
{c LT}{hline 19}{c RT}
{c |}{space 5}{it:frequency}{col 21}{c |}
{c |}{space 1}{it:column percentage}{col 21}{c |}
{c BLC}{hline 19}{c BRC}

violencety {c |}    members_coerced
   pe_beat {c |}        no        yes {c |}     Total
{hline 11}{c +}{hline 22}{c +}{hline 10}
         0 {c |}{res}       355         41 {txt}{c |}{res}       396 
           {txt}{c |}{res}     81.80      69.49 {txt}{c |}{res}     80.32 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
         1 {c |}{res}        79         18 {txt}{c |}{res}        97 
           {txt}{c |}{res}     18.20      30.51 {txt}{c |}{res}     19.68 
{txt}{hline 11}{c +}{hline 22}{c +}{hline 10}
     Total {c |}{res}       434         59 {txt}{c |}{res}       493 
           {txt}{c |}{res}    100.00     100.00 {txt}{c |}{res}    100.00 

{txt}
{com}.         
.         * label for plotting
.         label define coerced 1 "Without coercion" 2 "With coercion"
{txt}
{com}.         label value members_coerced coerced
{txt}
{com}.         
.         *  Figure 5a. sexual violence
.         #delimit ;
{txt}delimiter now ;
{com}.                 spineplot  violencetype_sexual members_coerced if members_coerced <3,
>                 bar1(color(black*0.9)) bar2(color(black*0.6)) percent
>                 graphregion(color(white))
>                 title("Sexual Violence" "" "", size(large) color(black))
>                 xti(% Groups using coercion, axis(1) size(medlarge)) 
>                 xla(0(25)100, axis(1) labsize(medlarge)) 
>                 yti(% Violence Type Sexual Violence, axis(2) size(medlarge)) 
>                 yla(0(25)100, axis(2) labsize(medlarge)) 
>                 legend(off)
>                 ttext(35 40  "89.86%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(35 88  "62.71%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(95 40  "10.14%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(95 88  "37.29%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 xti("", axis(2) size(medlarge)) 
>                 xla(, axis(2) labsize(medlarge)) 
>        
>         ;
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         graph save Figure5a.gph, replace
{txt}(note: file Figure5a.gph not found)
{res}{txt}(file Figure5a.gph saved)

{com}.         
.         *  Figure 5b. killings
.         #delimit ;
{txt}delimiter now ;
{com}.                 spineplot  violencetype_kill members_coerced if members_coerced <3,
>                 bar1(color(black*0.9)) bar2(color(black*0.6)) percent
>                 graphregion(color(white))
>                 title("Killings" "" "", size(large) color(black))
>                 xti(% Groups using coercion, axis(1) size(medlarge)) 
>                 xla(0(25)100, axis(1) labsize(medlarge)) 
>                 yti(% Violence Type Killing, axis(2) size(medlarge)) 
>                 yla(0(25)100, axis(2) labsize(medlarge)) 
>                 legend(off)
>                 ttext(25 40  "50.69%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(25 88  "38.98%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(75 40  "49.31%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(75 88  "61.02%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 xti("", axis(2) size(medlarge)) 
>                 xla(, axis(2) labsize(medlarge)) 
>        
>         ;
{res}{txt}
{com}.         # delimit cr            
{txt}delimiter now cr
{com}.         graph save Figure5b.gph, replace
{txt}(note: file Figure5b.gph not found)
{res}{txt}(file Figure5b.gph saved)

{com}.         
.         * Figure 5c. beatings
.         
.                 * label variable newly for legend in combined plot
.                 label def combi 1 "Violence type used" 0"Violence type not used"
{txt}
{com}.                 label val violencetype_beat combi
{txt}
{com}.         
.         #delimit ;
{txt}delimiter now ;
{com}.                 spineplot  violencetype_beat members_coerced if members_coerced <3,
>                 bar1(color(black*0.9)) bar2(color(black*0.6)) percent
>                 graphregion(color(white))
>                 title("Beatings" "" "", size(large) color(black))
>                 xti(% Groups using coercion, axis(1) size(medlarge)) 
>                 xla(0(25)100, axis(1) labsize(medlarge)) 
>                 yti(% Violence Type Beatings, axis(2) size(medlarge)) 
>                 yla(0(25)100, axis(2) labsize(medlarge)) 
>                 legend(size(small) bmargin(small)  region(lcolor(white)))
>                 ttext(40 40  "81.80%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(40 88  "69.49%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(90 40  "18.20%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 ttext(90 88  "30.51%" "", place(e) size(medlarge) orientation(horizontal) col(white) )
>                 xti("", axis(2) size(medlarge)) 
>                 xla(, axis(2) labsize(medlarge)) 
>        
>         ;
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         graph save Graph Figure5c.gph, replace
{txt}(note: file Figure5c.gph not found)
{res}{txt}(file Figure5c.gph saved)

{com}.         
. 
.         * combine 3 figures into panel
.         #delimit ;
{txt}delimiter now ;
{com}.                 grc1leg Figure5a.gph Figure5b.gph Figure5c.gph, 
>                 ycommon xcommon row(1)
>                 graphregion(color(white)) legendfrom(Figure5c.gph)
>         ;
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         
.         graph display, ysize(5) xsize(17)
{res}{txt}
{com}.         graph export  "figures/Figure5.pdf", replace
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure5.pdf written in PDF format)

{com}.         
.         erase "Figure5a.gph" // clean-up: erase temporary files from working directory
{txt}
{com}.         erase "Figure5b.gph" 
{txt}
{com}.         erase "Figure5c.gph"
{txt}
{com}.                         
.                         
. * Figure 6. Pedigree of PGMs
. *--------------------------------------------------      
.         
.         * get percentages 
.         tab prior_group, m // 61.7; 2.4; 35.9

{txt}prior_group {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
         no {c |}{res}        311       61.71       61.71
{txt}        yes {c |}{res}        181       35.91       97.62
{txt}    unclear {c |}{res}         12        2.38      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        504      100.00
{txt}
{com}.         tab prior_armed if prior_group==2, m // 10.5; 8.8; 80.7

{txt}prior_armed {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
         no {c |}{res}         19       10.50       10.50
{txt}        yes {c |}{res}        146       80.66       91.16
{txt}    unclear {c |}{res}         16        8.84      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        181      100.00
{txt}
{com}.         tab prior_rebel if prior_armed==2, m // 54.8; 4.1; 41.1

{txt}prior_rebel {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
         no {c |}{res}         80       54.79       54.79
{txt}        yes {c |}{res}         60       41.10       95.89
{txt}    unclear {c |}{res}          6        4.11      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        146      100.00
{txt}
{com}. 
.         
. * Figure 7. Three most common causes of PGM termination, by government link 
. *--------------------------------------------------     
. 
.         * generate indicator for PGMs not terminated yet
.         gen termtype_not_terminated = 0
{txt}
{com}.         replace termtype_not_terminated = 1 if year_terminated ==.  
{txt}(189 real changes made)

{com}.                 
.         * get combinations
.         
.                 * informal PGMs
.                 egen term1 = group(termtype_disarmed termtype_gov_change termtype_gov_defect termtype_border_change termtype_pgm_defect termtype_integrate termtype_unclear) if termtype_not_terminated ==0 & government_relation ==1, label
{res}{txt}(309 missing values generated)

{com}.                 tab term1

    {txt}see notes {c |}      Freq.     Percent        Cum.
{hline 14}{c +}{hline 35}
0 0 0 0 0 0 0 {c |}{res}          1        0.51        0.51
{txt}0 0 0 0 0 0 1 {c |}{res}          8        4.10        4.62
{txt}0 0 0 0 0 1 0 {c |}{res}          7        3.59        8.21
{txt}0 0 0 0 1 0 0 {c |}{res}         11        5.64       13.85
{txt}0 0 0 0 1 1 0 {c |}{res}          2        1.03       14.87
{txt}0 0 0 1 0 0 0 {c |}{res}         16        8.21       23.08
{txt}0 0 1 0 0 0 0 {c |}{res}         38       19.49       42.56
{txt}0 0 1 0 0 1 0 {c |}{res}          2        1.03       43.59
{txt}0 0 1 0 1 0 0 {c |}{res}          1        0.51       44.10
{txt}0 1 0 0 0 0 0 {c |}{res}         88       45.13       89.23
{txt}0 1 0 0 0 1 0 {c |}{res}          1        0.51       89.74
{txt}0 1 0 0 1 0 0 {c |}{res}          2        1.03       90.77
{txt}1 0 0 0 0 0 0 {c |}{res}         15        7.69       98.46
{txt}1 0 0 0 0 1 0 {c |}{res}          1        0.51       98.97
{txt}1 0 1 0 0 0 0 {c |}{res}          2        1.03      100.00
{txt}{hline 14}{c +}{hline 35}
        Total {c |}{res}        195      100.00
{txt}
{com}.         
.                 * most common three
.                         * 1 government changed: 45.13%  (0100000)
.                         * 2 government defected: 19.49% (0010000)
.                         * 3 border change: 8.21%                (0001000)
.                 
.                 * semi-official PGMs
.                 egen term2 = group(termtype_disarmed termtype_gov_change termtype_gov_defect termtype_border_change termtype_pgm_defect termtype_integrate termtype_unclear) if termtype_not_terminated ==0 & government_relation ==2, label
{res}{txt}(418 missing values generated)

{com}.                 tab term2

    {txt}see notes {c |}      Freq.     Percent        Cum.
{hline 14}{c +}{hline 35}
0 0 0 0 0 0 1 {c |}{res}          5        5.81        5.81
{txt}0 0 0 0 0 1 0 {c |}{res}          9       10.47       16.28
{txt}0 0 0 0 1 0 0 {c |}{res}          5        5.81       22.09
{txt}0 0 0 1 0 0 0 {c |}{res}          5        5.81       27.91
{txt}0 0 1 0 0 0 0 {c |}{res}         23       26.74       54.65
{txt}0 0 1 0 0 1 0 {c |}{res}          1        1.16       55.81
{txt}0 0 1 0 1 0 0 {c |}{res}          1        1.16       56.98
{txt}0 1 0 0 0 0 0 {c |}{res}         27       31.40       88.37
{txt}0 1 1 0 0 0 0 {c |}{res}          2        2.33       90.70
{txt}1 0 0 0 0 0 0 {c |}{res}          5        5.81       96.51
{txt}1 0 0 1 0 0 0 {c |}{res}          1        1.16       97.67
{txt}1 0 1 0 0 0 0 {c |}{res}          1        1.16       98.84
{txt}1 1 0 0 0 0 0 {c |}{res}          1        1.16      100.00
{txt}{hline 14}{c +}{hline 35}
        Total {c |}{res}         86      100.00
{txt}
{com}.         
.                 * most common three
.                         * 1 government changed: 31.40%  (0100000)
.                         * 2 government defected: 26.74% (0010000)
.                         * 3 PGM integrated: 10.47 %             (0000010)
. 
.                 
.         * pre-step 1: create indicator variable 
.         gen kat1 = 0
{txt}
{com}.         replace kat1 =1 if term2== 8  // most common semi-official: government changed
{txt}(27 real changes made)

{com}.         replace kat1 =2 if term2== 5  // 2nd most common semi-official: government defected
{txt}(23 real changes made)

{com}.         replace kat1 =3 if term2== 2  // 3rd most common semi-official: PGM integrated
{txt}(9 real changes made)

{com}.         replace kat1 =1 if term1== 10 // most common informal: government changed
{txt}(88 real changes made)

{com}.         replace kat1 =2 if term1== 7  // 2nd most common informal: government defected
{txt}(38 real changes made)

{com}.         replace kat1 =3 if term1== 6  // 3rd most common informal: Border changed
{txt}(16 real changes made)

{com}.         replace kat1=. if term2==. & term1==.
{txt}(223 real changes made, 223 to missing)

{com}.         
.         * pre-Step 2: create dummy variables for plotting
.         tab kat1, gen(tum)

       {txt}kat1 {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res}         80       28.47       28.47
{txt}          1 {c |}{res}        115       40.93       69.40
{txt}          2 {c |}{res}         61       21.71       91.10
{txt}          3 {c |}{res}         25        8.90      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}        281      100.00
{txt}
{com}.         
. 
.         * plot and edit graph to hide dummy1 bar = others (necessary, otherwise % wrong)
.         #delimit ;
{txt}delimiter now ;
{com}.                 graph hbar tum2 tum3 tum4 tum1  if government_relation !=0 , 
>                 over(government_relation, relabel(1 "Informal" 2 "Semi-official"))  percent
>                 graphregion(color(white))
>                 ylabel( none, nogrid)
>                 yscale(lstyle(none))
>                 ytitle("")
>                 bar(1, color(black*0.9)) bar(2, color(black*.6)) bar(3, color(blackue*0.4)) bar(4, color(blackue*0.28))
>                 legend(off)
>                 ttext(1 20  "10.47%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 31  "26.74%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 41  "31.40%" "", place(e) size(small) orientation(horizontal) col(white) ) 
>                 
>                 ttext(48 20  "PGM integreated", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(48 31  "Government defected", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(48 41  "Government changed", place(e) size(small) orientation(horizontal) col(black) ) 
>                 
>                 ttext(1 71  "8.21%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 82  "19.49%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 ttext(1 93  "45.13%" "", place(e) size(small) orientation(horizontal) col(white) )  
>                 
>                 ttext(48 71  "Border change", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(48 82  "Government defected", place(e) size(small) orientation(horizontal) col(black) )  
>                 ttext(48 93  "Government changed", place(e) size(small) orientation(horizontal) col(black) )  
>         ;
{res}{p 0 4 2}
{txt}(note:  named style
blackue not found in class
color,  default attributes used)
{p_end}
{p 0 4 2}
{txt}(note:  named style
blackue not found in class
color,  default attributes used)
{p_end}
{p 0 4 2}
{txt}(note:  named style
blackue not found in class
color,  default attributes used)
{p_end}
{p 0 4 2}
{txt}(note:  named style
blackue not found in class
color,  default attributes used)
{p_end}
{res}{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}.         
.         gr_edit .plotregion1.bars[5].draw_view.setstyle, style(no)
{res}{txt}
{com}.         gr_edit .plotregion1.bars[1].draw_view.setstyle, style(no)
{res}{txt}
{com}.         gr_edit .scaleaxis.reset_rule 0 70 1 , tickset(major) ruletype(range) 
{res}{txt}
{com}.         gr_edit .scaleaxis.style.editstyle majorstyle(tickstyle(show_labels(no))) editcopy
{res}{txt}
{com}.         gr_edit .scaleaxis.style.editstyle majorstyle(tickstyle(show_ticks(no))) editcopy
{res}{txt}
{com}.         
.         graph export  "figures/Figure7.pdf", replace
{txt}(file /Users/gu48zez/Dropbox/PGMDv2 data paper/R&P_acceptance/replication_material/figures/Figure7.pdf written in PDF format)

{com}. 
{txt}end of do-file

{com}. do "/var/folders/v0/tsk0kfzs2r32jh_z9txl7k7c031ymf/T//SD64227.000000"
{txt}
{com}. 
.         set more off
{txt}
{com}.         clear all
{txt}
{com}.   
. ********************************************************************************
. * Setting working directory 
. ********************************************************************************
.         cd "/Users/gu48zez/Dropbox/PGMDv2 data paper/create_datasets/country_year_v2"
{res}/Users/gu48zez/Dropbox/PGMDv2 data paper/create_datasets/country_year_v2
{txt}
{com}.         *cd "/create_data/" //Set path for your working directory here
.                 * Example for Mac: cd "/Users/name/Dektop/create_data" 
.                 * Example for Windows "C:\Users\name\Desktop\create_data" 
.         
. 
.         
. ********************************************************************************
. * Load group-level dataset
. ********************************************************************************
. 
.         
.         use "pgmd_v2_2020_09_03_label_final.dta"
{txt}
{com}. 
{txt}end of do-file

{com}. do "/var/folders/v0/tsk0kfzs2r32jh_z9txl7k7c031ymf/T//SD64227.000000"
{txt}
{com}. 
.         * Manual coding of interrupted pgms
.         do 2_interrupted_pgm.do
{txt}
{com}. *********
. * Interrupted pgms to create spell dataset
. * K.Paula, 19.07.18
. * Stata version: 15
. **********
. 
. *********
. * Interrupted pgms to create spell dataset
. * Update from S. Carey, 16 Feb 2021
. * Stata version: 16
. **********
. 
. 
. 
. * I. Adding rows of observation for interruped pgms
. *-----------------------------------------------------
. 
. 
.         * Afghanistan
.                 
.                 * ID 426 Forces of Ismail Khan / Herat militia: 2 spells, 2001-2004 and 2012-11-14 – 2013-01-01
.                 expand 2 if id == 426
{txt}(1 observation created)

{com}.                 
.                 * ID 206  Uzbek-Junbesh-e-Milli: 3 spells 20/04/1989 until 1993, then again pro-gov August 1996 until 25 September 1996, then again 22 December 2001 – 2007, Pro-government again on 16 June 2009 - NA. 
.                 expand 4 if id == 206
{txt}(3 observations created)

{com}.                 
.                 * ID 209 Ittehad Islami: 2 spells 29/06/1992 - Sept 1996 | Dec 2003- N.A.
.                 expand 2 if id == 209
{txt}(1 observation created)

{com}.                 
.                 * ID 208 Jamaat Islami: 2 spells 1992-04-28 – 1996-09-27 | 2001-12-22 –
.                 expand 2 if id == 208
{txt}(1 observation created)

{com}.                 
.                 
.         * Bangladesh 
.                 * ID 178 Bangladesh Chhatra League:  2 spells 23 June 1996 - 12 July 2001 | 6 Jan 2009- N.A.
.                 expand 2 if id == 178
{txt}(1 observation created)

{com}.                 
.                 * ID 177 Jatiyatabadi Chhatra Dal (JCD): 3 spells  1 Jan 1979 - 24/3/1982 | 20/03/1991 - 30/03/1996 |  10/10/2001 - 29/10/2006
.                 expand 3 if id == 177
{txt}(2 observations created)

{com}.                 
.                 
.         * Congo-K
.                 * ID 430 FDLR: 3 spells Jan 1998 - July 2002 | Sept 2007- Dec 2008 | July 2013 - NA
.                 expand 3 if id == 430
{txt}(2 observations created)

{com}.                 
.                 
.         * Georgia       
.                 * ID 165 Forest Brothers: 2 spells 1998-01-01 – 2004-01-25 | 2005-11-17- NA --> not relevant for country year aggrgation
.                 expand 2 if id == 165
{txt}(1 observation created)

{com}.         
.         
.         * Iraq          
.                 * ID 234 Awakening Groups / Sahwa: 2 spells 2008-11 – 2011-12 | 2014 - NA
.                 expand 2 if id == 234
{txt}(1 observation created)

{com}.                         
.                 * ID 229 Popular Army/ Jerusalem Army: 2 spells 1970-01-01 to 1991-02-28 | and from 1992-07-02 until 2003-04-09 --> not relevant for country year aggregation!
.                 expand 2 if id == 229
{txt}(1 observation created)

{com}. 
.                 
.         * Indonesia
.                 * ID 318 Halilintar: 2 spells 1975-01-01 -– 1982-12-31 |  1995-01-01 – 2003-02-25
.                 expand 2 if id == 318
{txt}(1 observation created)

{com}.                 
.                 
.         * Libya
.                 * ID 599 Tripoli Military Council: 2 spells 2012 – 2012-08-08 | 2014-03-01 – 2014-08-04
.                 expand 2 if id == 599
{txt}(1 observation created)

{com}.                 
.                 
.         * Malawi
.                 * ID 480 Youth Cadets: 2 spells 2011-04-20 – 2012-04-07 | 2014-05-31 – 2020-06-28  
.                 expand 2 if id == 480           
{txt}(1 observation created)

{com}.         
.         
.         * Nepal         
.                 * ID 462 Young Communist League: 2 spells 18/08/2008 – 25/05/2009 | 29/08/2011 – 14/03/2013
.                 expand 2 if id == 462
{txt}(1 observation created)

{com}.         
.         
.         * Pakistan 
.                 * ID 182 Jamaat-i-Islami: 2 spells  July 1977-June 1988 | Nov 1990 - May 1992
.                 expand 2 if id == 182
{txt}(1 observation created)

{com}.         
.                 * ID 183 Muttahida Quami Movement: 4 spells Nov 1987 - Oct 1989| Nov 1990-June 1992 | 1997-02-17 – 1998-10 | Oct 2002-Feb 2013 (First spell not relevant for country year aggregation)
.                 expand 4 if id == 183
{txt}(3 observations created)

{com}.         
.         
.         * Philippines
.                 * ID 570 Tagum Death Squads: 2 spells 1998-07-01 — 2001-12-01 | 2004-01-01 — 2013-12-01
.                 expand 2 if id == 570
{txt}(1 observation created)

{com}.                 
.                 
.         * Sudan 
.                 * ID 276 Fertit Militiamen: 2 spells 1987-01-19 - late 1990 | restart 1997 - 2007-11-17
.                 expand 2 if id == 276
{txt}(1 observation created)

{com}.         
.         
.         * Zimbabwe
.                 * ID 104 War Vets: 2 spells 2000-04-21 — 2016-06-01 |  2017-11-24 — NA --> not relevant for country year aggregation!
.                 expand 2 if id == 104
{txt}(1 observation created)

{com}.                 
.                 * ID 101 Youth Service Brigade / Green Bombers: 3 spells 2000-02-12 – 2009-02-01 | 2010-01-01 – 2012-01-01 | 2017-01-01 – 2017-12-31
.                 expand 3 if id == 101
{txt}(2 observations created)

{com}. 
.         * Others not coded since two spells within a year --> would result in wrong aggregation based on the year level!
.                 * SOMALIA ID 609 Raskamboni/ Raas Kaambooni: 2 spells 20/08/2012 – 31/01/2013, 01/09/2013- --> not relevant for country year aggregation! Would results in wrong counting since two spells within one year
.                 * HAITI ID 363 Ton Ton Macoutes Type 1: 2 spells 12 Feb 1986-02-12 until 1991-02-97 | 1991-09-30 - 1994-10-19 --> not relevant for country year aggregation! Would results in wrong counting since two spells within one year
.                 * LIBYA ID 595 Al-Zintan Military Council: 2 spells 2011-08-23 – 2014-07-01 | 2014-08-04 – NA
.                 
.                 
.         
. * II. Generate spell-id
. *--------------------------------
.         
.         
.         bysort id: gen spell = _n
{txt}
{com}.         label var spell "spell of interrupted PGMs"
{txt}
{com}. 
.         
. * III. Recode all spells
. *---------------------------------
.         * Rule: 
.         * if only end or start year:  end date = 31.12 XXXX, start date = 01.01.XXXX
.         * if only end or start month: end date = 31/30. XX.XXXX, start date = 01.XX.XXXX
.         
.         
.         
.         * Afghanistan
.                 * ID 426 Forces of Ismail Khan / Herat militia: 2 spells, 2001-2004 and 2012-11-14 – 2013-01-01
.                 replace date_terminated = td(31dec2004) if id==426 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(14nov2012) if id==426 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(31dec2012) if id==426 & spell==2
{txt}(1 real change made)

{com}.         
.                 * ID 206  Uzbek-Junbesh-e-Milli: 4 spells 20/04/1989 until 1993, then again pro-gov August 1996 until 25 September 1996, then again 22 December 2001 – 2007, Pro-government again on 16 June 2009 - NA. 
.                 replace date_terminated = td(31dec1993) if id==206 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01aug1996) if id ==206 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(25sep1996) if id == 206 & spell == 2
{txt}(1 real change made)

{com}.                 replace date_formed = td(22dec2001) if id ==206 & spell ==3
{txt}(1 real change made)

{com}.                 replace date_terminated = td(31dec2007) if id == 206 & spell == 3
{txt}(1 real change made)

{com}.                 replace date_formed = td(16jun2009) if id ==206 & spell ==4
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 206 & spell == 4
{txt}(0 real changes made)

{com}.                 
.                 * ID 209 Ittehad Islami: 2 spells 29/06/1992 - Sept 1996 | Dec 2003- N.A. // checked for last acitiviy: 2004 
.                 replace date_terminated = td(30sep1996) if id==209 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01dec2003) if id ==209 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 209 & spell == 2
{txt}(0 real changes made)

{com}.                 
.                 * ID 208 Jamaat Islami: 1992-04-28 – 1996-09-27 | 2001-12-22 – N.A. // checked for last activity: 2012
.                 replace date_terminated = td(27sep1996) if id==208 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(22dec2001) if id ==208 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 208 & spell == 2
{txt}(0 real changes made)

{com}.                 
.                 
.         * Bangladesh 
.                 * ID 178 Bangladesh Chhatra League:  2 spells 23 June 1996 - 12 July 2001 | 6 Jan 2009- N.A. // checked for last activity = 2014
.                 replace date_terminated = td(12jul2001) if id==178 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(06jan2009) if id ==178 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 178 & spell == 2
{txt}(0 real changes made)

{com}.                 
.                 * ID 177 Jatiyatabadi Chhatra Dal (JCD): 3 spells  1 Jan 1979 - 24/3/1982 | 20/03/1991 - 30/03/1996 |  10/10/2001 - 29/10/2006
.                 replace date_terminated = td(24mar1982) if id==177 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(20mar1991) if id ==177 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(30mar1996) if id == 177 & spell == 2
{txt}(1 real change made)

{com}.                 replace date_formed = td(10oct2001) if id ==177 & spell ==3
{txt}(1 real change made)

{com}.                 replace date_terminated = td(29oct2006) if id == 177 & spell == 3
{txt}(0 real changes made)

{com}.                 
.                 
.         * Congo-K
.                 * ID 430 FDLR: 3 spells Jan 1998 - July 2002 | Sept 2007- Dec 2008 | July 2013 - NA // checked for last activity = 2014
.                 replace date_terminated = td(31jul2002) if id==430 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01sep2007) if id ==430 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(31dec2008) if id == 430 & spell == 2
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jul2013) if id ==430 & spell ==3
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 430 & spell == 3
{txt}(0 real changes made)

{com}.                 
.                 
.         * Georgia       
.                 * ID 165 Forest Brothers: 2 spells 1998-01-01 – 2004-01-25 | 2005-11-17- NA --> not relevant for country year aggrgation // checked for last activity 2007
.                 replace date_terminated = td(25jan2004) if id==165 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(17nov2005) if id ==165 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 165 & spell == 2
{txt}(0 real changes made)

{com}.                 
.                 
.         * Iraq  
.                 * ID 234 Awakening Groups / Sahwa: 2 spells 2008-11 – 2011-12 | 2014 - NA
.                 replace date_terminated = td(31dec2008) if id==234 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan2014) if id==234 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id == 234 & spell==2
{txt}(0 real changes made)

{com}.                 
.                 * ID 229 Popular Army/ Jerusalem Army: 2 spells 1970-01-01 to 1991-02-28 | and from 1992-07-02 until 2003-04-09 --> not relevant for country year aggregation!
.                 replace date_terminated = td(28feb1991) if id==229 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(02jul1992) if id ==229 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(09apr2003) if id == 229 & spell == 2
{txt}(0 real changes made)

{com}. 
.                 
.         * Indonesia
.                 * ID 318 Halilintar: 2 spells 1975-01-01 -– 1982-12-31 |  1995-01-01 – 2003-02-25
.                 replace date_terminated = td(31dec1982) if id==318 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan1995) if id==318 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(25feb2003) if id==318 & spell==2
{txt}(0 real changes made)

{com}. 
.                 
.         * Libya
.                 * ID 599 Tripoli Military Council: 2 spells 2012 – 2012-08-08 | 2014-03-01 – 2014-08-04
.                 replace date_terminated = td(08aug2012) if id==599 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01mar2014) if id==599 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(04aug2014) if id==599 & spell==2
{txt}(0 real changes made)

{com}. 
.                 
.         * Malawi
.                 * ID 480 Youth Cadets (DPP): 2 spells 2011-04-20 - 2012-04-07 | 2014-05-31 – 2020-06-28
.                 replace date_terminated = td(07apr2012) if id==480 & spell==1
{txt}(0 real changes made)

{com}.                 replace date_formed = td(31may2014) if id==480 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id==480 & spell==2  /* USED FOR VERSION UP TO 2014  */
{txt}(1 real change made, 1 to missing)

{com}.                 *replace date_terminated = td(28jun2020) if id==480 & spell==2  /* RUN ONLY FOR VERSION UP TO 2020 ! */
.                 
.                 
.         * Nepal         
.                 * ID 462 Young Communist League: 2 spells 18/08/2008 – 25/05/2009 | 29/08/2011 – 14/03/2013
.                 replace date_terminated = td(25may2009) if id==462 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(29aug2011) if id ==462 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(14mar2013) if id == 462 & spell == 2
{txt}(0 real changes made)

{com}.                 
.         
.         * Pakistan
.                 * ID 182 Jamaat-i-Islami: 2 spells  July 1977-June 1988 | Nov 1990 - May 1992
.                 replace date_terminated = td(01jun1988) if id==182 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01nov1990) if id ==182 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(01may1992) if id == 182 & spell == 2
{txt}(0 real changes made)

{com}.                 
.                 * ID 183 Muttahida Quami Movement: 4 spells Nov 1987 - Oct 1989| Nov 1990-June 1992 | 1997-02-17 – 1998-10 | Oct 2002-Feb 2013 (First spell not relevant for country year aggregation)
.                 replace date_terminated = td(31oct1989) if id== 183 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01nov1990) if id == 183 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(30jun1992) if id == 183 & spell == 2
{txt}(1 real change made)

{com}.                 replace date_formed = td(17feb1997) if id == 183 & spell ==3
{txt}(1 real change made)

{com}.                 replace date_terminated = td(01oct1998) if id == 183 & spell == 3       
{txt}(1 real change made)

{com}.                 replace date_formed = td(01oct2002) if id == 183 & spell ==4
{txt}(1 real change made)

{com}.                 replace date_terminated = td(27feb2013) if id == 183 & spell == 4
{txt}(1 real change made)

{com}.                 
.                 
.         * Philippines
.                 * ID 570 Tagum Death Squads: 2 spells 1998-07-01 — 2001-12-01 | 2004-01-01 — 2013-12-01
.                 replace date_terminated = td(01dec2001) if id==570 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan2004) if id==570 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(01dec2013) if id==570 & spell==2
{txt}(1 real change made)

{com}.                 
.                 
.         * Sudan 
.                 * ID 276 Fertit Militiamen: 2 spells 1986-01-01 - 1990-11-10 | restart 1997 - 2007-11-17
.                 replace date_terminated = td(10nov1990) if id==276 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan1997) if id ==276 & spell ==2
{txt}(1 real change made)

{com}.                 replace date_terminated =td(17nov2007) if id == 276 & spell == 2
{txt}(1 real change made)

{com}.         
. 
.         * Zimbabwe
.                 * ID 104 War Vets: 2 spells 2000-04-21 — 2016-06-01 |  2017-11-24 — NA --> not relevant for country year aggregation!
.                 replace date_terminated = td(01jun2016) if id==104 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(24nov2017) if id==104 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = . if id==104 & spell==2
{txt}(0 real changes made)

{com}.                 
.                 * ID 101 Youth Service Brigade / Green Bombers: 3 spells 2000-02-12 – 2009-02-01 | 2010-01-01 – 2012-01-01 | 2017-01-01 – 2017-12-31
.                 replace date_terminated = td(01feb2001) if id==101 & spell==1
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan2010) if id==101 & spell==2
{txt}(1 real change made)

{com}.                 replace date_terminated = td(31dec2011) if id==101 & spell==2
{txt}(1 real change made)

{com}.                 replace date_formed = td(01jan2017) if id==101 & spell==3
{txt}(1 real change made)

{com}.                 replace date_terminated = td(31dec2017) if id==101 & spell==3
{txt}(1 real change made)

{com}.         
.         
.         
. 
{txt}end of do-file

{com}. 
.         * Again creating termination variable, now taking interruption into account 
.         drop year_formed year_terminated year_terminated_alt 
{txt}
{com}.         gen year_formed = year(date_formed)
{txt}
{com}.         gen year_terminated = year(date_terminated)
{txt}(190 missing values generated)

{com}. 
.         
.         drop termination        //the textfield
{txt}
{com}.         gen termination_alt=. // use alternative coding of termination, using last_activity
{txt}(531 missing values generated)

{com}.         replace termination_alt = year_terminated if year_terminated !=.  //  If date_dissolved present, take this date (341 cases)
{txt}(341 real changes made)

{com}.         
.         * If date_dissolved = "NA", and         
. 
.                 * last_activity = "NA" than use 2014 as termination 
.                 replace termination_alt = 2014 if year_terminated==. & last_activity==. 
{txt}(7 real changes made)

{com}. 
.                 * last_activity >=2010, use 2014 as termination (141 cases)
.                 replace termination_alt = 2014 if year_terminated==. & last_activity >=2010 & last_activity!=.
{txt}(142 real changes made)

{com}.         
.                 * last activity < 2010 use date of last activity as termination date (41 cases)
.                 replace termination_alt = last_activity if year_terminated==. & last_activity<2010  & last_activity!=.
{txt}(41 real changes made)

{com}.                                 
. 
.         order id name country gwno last_activity date_formed year_formed date_terminated year_terminated  termination_alt spell government_relation gov_formed
{txt}
{com}.         save "PGMD_spell_v2.dta", replace       
{txt}(note: file PGMD_spell_v2.dta not found)
file PGMD_spell_v2.dta saved

{com}.         
. 
{txt}end of do-file

{com}. do "/var/folders/v0/tsk0kfzs2r32jh_z9txl7k7c031ymf/T//SD64227.000000"
{txt}
{com}.                         
.         * Streching data and aggregating counts 
.         gen spell_id = _n 
{txt}
{com}.         expand 34
{txt}(17,523 observations created)

{com}.         bys spell_id: gen year = 1980+_n // gen year variable 1981-2014
{txt}
{com}.         drop if year_formed > 2014
{txt}(68 observations deleted)

{com}.         
.         * Generate presence variable for counting
.         gen presence=0
{txt}
{com}.         replace presence=1 if year_formed <=year & termination_alt >= year
{txt}(4,892 real changes made)

{com}.         
.         
.         * Counts per country-year
. 
.                 * total counts per country-year
.                 sort country year
{txt}
{com}.                 bysort country year: egen presence_count=total(presence)        
{txt}
{com}.         
.                 * counts informal pgms per country-year
.                 bysort country year: egen h_informal=total(presence) if government_relation==1
{txt}(7004 missing values generated)

{com}.                 recode h_informal (.=0)
{txt}(h_informal: 7004 changes made)

{com}.                 bysort country year: egen presence_informal_count = max(h_informal)
{txt}
{com}. 
.                 * counts semiofficial pgms per country-year
.                 bysort country year: egen h_semi=total(presence) if government_relation==2
{txt}(11730 missing values generated)

{com}.                 recode h_semi (.=0)
{txt}(h_semi: 11730 changes made)

{com}.                 bysort country year: egen presence_semiofficial_count = max(h_semi)
{txt}
{com}.         
.                 * counts government formed militias per country and year
.                 bysort country year: egen h_gov_formed=total(presence) if gov_formed==2
{txt}(10608 missing values generated)

{com}.                 recode h_gov_formed (.=0)
{txt}(h_gov_formed: 10608 changes made)

{com}.                 bysort country year: egen presence_gov_formed_count = max(h_gov_formed)
{txt}
{com}.         
.                 * counts NOT government formed militias per country and year
.                 bysort country year: egen h_notgov_formed=total(presence) if gov_formed==1
{txt}(9044 missing values generated)

{com}.                 recode h_notgov_formed (.=0)
{txt}(h_notgov_formed: 9044 changes made)

{com}.                 bysort country year: egen presence_notgov_formed_count = max(h_notgov_formed)
{txt}
{com}. 
{txt}end of do-file

{com}. di 13.5-27
{res}-13.5

{com}. 13.5/9
{bf}{err}13.5{sf} is not a valid command name
{txt}{search r(199):r(199);}

{com}. di 0.098/0.036
{res}2.7222222

{com}. di 92.12/108.55
{res}.84864118

{com}. di 0.38/4
{res}.095

{com}. di 0.038/4
{res}.0095

{com}. di 0.15/4
{res}.0375

{com}. di 1-0.15
{res}.85

{com}. di 0.85/578
{res}.00147059

{com}. di 0.85/579
{res}.00146805

{com}. di 0.38/0.0015
{res}253.33333

{com}. di (0.0375)/(0.85/579)
{res}25.544118

{com}. di 16.43/4
{res}4.1075

{com}. di 92.13/579
{res}.15911917

{com}. di 4.11/0.16
{res}25.6875

{com}. di sqrt(0.16/579)
{res}.01662343

{com}. exp(0.06)-1
{err}command {bf}exp{sf} is unrecognized
{txt}{search r(199):r(199);}

{com}. di exp(0.06)-1
{res}.06183655

{com}. di exo(0.19)
{res}{err}unknown function exo()
{txt}{search r(133):r(133);}

{com}. di exp(0.19)
{res}1.2092496

{com}. 1.21-1
{bf}{err}1.21{sf} is not a valid command name
{txt}{search r(199):r(199);}

{com}. di 1.21-1
{res}.21

{com}. di 0.16/2
{res}.08

{com}. di 0.83/1594
{res}.0005207

{com}. di 0.08/0.0005207
{res}153.63933

{com}. di-5.045-0.137+6.225
{res}1.043

{com}. di exp(-1.043)
{res}.35239591

{com}. 1/(1+0.352)
{bf}{err}1{sf} is not a valid command name
{txt}{search r(199):r(199);}

{com}. dui 1/(1+0.352)
{err}command {bf}dui{sf} is unrecognized
{txt}{search r(199):r(199);}

{com}. di 1/(1+0.352)
{res}.73964497

{com}. 